﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Model;

namespace DAL
{
   public class FlowerModels:IFlowersModel
    {
       public static string Conns = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
       /// <summary>
       /// 花卉的显示
       /// </summary>
       /// <returns></returns>
       public List<Model.FlowersModel> getFlower(string FlowersGiftsType, string FlowersStockType)
        {
            using(SqlConnection sql=new SqlConnection (Conns))
            {
                string search = "";
                if (FlowersGiftsType!=null)
                {
                    search += " and FlowersGiftsType='" + FlowersGiftsType + "'";
                }
                if (FlowersStockType!=null)
                {
                    search += " and FlowersStockType='" + FlowersStockType + "'";
                }
                sql.Open();
                string sqlstr = "select FlowersID,FlowersName,Sales_unit_Price,FlowersStock,Flowersimg,FlowersAddTime,FlowersStocktype from FlowersTable where FlowerState=1";
                SqlCommand cmd=new SqlCommand (sqlstr+search,sql);
                SqlDataAdapter da=new SqlDataAdapter (cmd);
                DataTable ta=new DataTable ();
                da.Fill(ta);
                List<FlowersModel> list=new List<FlowersModel> ();
                foreach(DataRow i in ta.Rows)
                {
                    FlowersModel flower = new FlowersModel()
                    {
                        FlowersID = Convert.ToInt32(i["FlowersID"]),
                        FlowersName = i["FlowersName"].ToString(),
                        Sales_unit_price = Convert.ToInt32(i["Sales_unit_Price"]),
                        FlowersStock = Convert.ToInt32(i["FlowersStock"]),
                        FlowersImg = i["Flowersimg"].ToString(),
                        FlowersAddTime = Convert.ToDateTime(i["FlowersAddTime"]),
                        FlowersStockType = i["FlowersStockType"].ToString()

                    };
                    list.Add(flower);
                }
                return list;
            }

        }
    }
}
